import request from '@/common/request.js';




import endFinish from "../../static/workflow/wf_end_complete.png";
import startFinish from "../../static/workflow/wf_start_complete.png";
import endIcon from "../../static/workflow/wf_end.png";
import wf_manual from "../../static/workflow/wf_manual.png";
import wf_manual_complete from "../../static/workflow/wf_manual_complete.png";
import running from "../../static/workflow/wf_manual_running.gif";


//获取通讯录
export function getAddressBook(config) {
	return request.httpTokenRequest(config)
}

// 登录
export function loginOA(config) {
	return request.httpTokenRequest(config)
}


// 获取待办消息
export async function getTodoAction(config) {
	return request.httpTokenRequest(config)
}

// 附件上传
export async function uploadFilePromise(config) {
	return request.uploadFilePromise(config)
}

export function notificationEvent(type, dec) {
	uni.showToast({
		icon: type,
		duration: 3000,
		title: dec,
	});

}


/**
 * 根据消息审批类型 获取审批名称
 * @param {Object} bizType
 */
export function getAuditPageTitle(bizType) {
	let title = ''
	switch (bizType) {
		case 355:
			title = '用章申请单审批';
			break;
		case 350:

			title = '费用报销单审批';
			break;
		case 351:
			title = '请假申请单审批';
			break;
		case 352:

			title = '加班申请单审批';
			break;
		case 353:
			title = '出差申请单审批';
			break;
		default:
			title = ''

	}
	return title;
}

export function getUser() {
	return uni.getStorageSync("userInfo")
}

export function getCompanyId() {
	const company = uni.getStorageSync("companny")
	const com = company ? company.split("@")[1] : "";
	return com
}

export function getWorkFlowImg(start, end, item, historyNodeList) {
	// 流程图的图片
	if (start) {
		return startFinish
	}
	if (end) {
		if (item) {
			if (Object.keys(item).length > 0 && item.isDone === 1) {
				return endFinish;
			}
			if (Object.keys(item).length > 0 && item.isDone === 0) {
				return endIcon;
			}

		}
		return endIcon;
	}
	if (item.seq - 1 <= 0) {
		if (item.isDone === 1) {
			return wf_manual_complete;
		}
		return running;

	}
	if (item.seq - 1 > 0) {
		const nodes = historyNodeList.length > 0 && historyNodeList.filter(node => node.seq === item.seq - 1)[0];

		if (item.isDone === 0 && nodes && nodes.isDone === 0) {
			return wf_manual;
		}

		if (item.isDone === 0 && nodes && nodes.isDone === 1) {
			return running;
		}

		if (item.isDone === 1 && nodes && nodes.isDone === 1) {
			return wf_manual_complete;
		}
	}
}


// export async function query(params) {
//   return request(`${config.BASE_URL}/user/getUserByCondition`, {
//     method: `POST`,
//     body: {
//       ...params,
//       method: `post`,
//     },
//   });
// }